﻿SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
GO
CREATE VIEW SYS_BLOG_FIELDS
AS
SELECT 
	t.id as idx,
	CASE 
		WHEN c.ColumnId IS NOT NULL THEN c.DisplayName + ' ('+t.name+')'
		ELSE t.name
	END as identyfikator
FROM 
	n_Tree t
	INNER JOIN N_Tree tp ON t.parent = tp.id
	LEFT JOIN bht_Columns c ON t.id = c.ColumnId
WHERE 
	tp.name = 'BLOG_POSTS'
	AND t.del = 0
GO
CREATE PROCEDURE bhp_Temp_ModStructure
AS
BEGIN

	DECLARE
		@ViewFieldsId				INT,
		@BlogConfigurationId		INT

	EXEC [dbo].[n_ViewAdd] @name = N'SYS_BLOG_FIELDS', @user = 9999999
		SELECT @ViewFieldsId = id FROM n_Tree t WHERE t.name = 'SYS_BLOG_FIELDS' AND parent = 0
	SELECT @BlogConfigurationId = id FROM n_Tree t WHERE t.name = 'SYS_BLOG_CONFIGURATION' AND parent = 0

	EXEC [dbo].[n_ColFNAdd] @tab = @BlogConfigurationId, @name = N'widoczne_pola', @rel = @ViewFieldsId, @user = 9999999
	
END
GO
EXEC bhp_Temp_ModStructure
GO
DROP PROCEDURE bhp_Temp_ModStructure
